import AutoImport from "unplugin-auto-import/vite";
import uni from "@dcloudio/vite-plugin-uni";
const pathSrc = path.resolve(__dirname, "./");
import path from "path";
import viteCompression from "vite-plugin-compression";
export default {
  plugins: [
    uni(),
    AutoImport({
      imports: ["vue", "uni-app", "pinia"],
      dirs: ["./store/modules", "./public", "./utils"],
      vueTemplate: true,
      dts: path.resolve(pathSrc, "types", "auto-imports.d.ts"),
      include: [
        /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        /\.vue$/,
        /\.vue\?vue/, // .vue
      ],
    }),
    viteCompression({
      filter: /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i, // 需要压缩的文件
      threshold: 10240, // 文件容量大于这个值进行压缩 单位kb
      algorithm: "gzip", // 压缩方式
      ext: "gz", // 后缀名
      deleteOriginFile: false, // 压缩后是否删除压缩源文件,不能删除
    }),
  ],
  server: {
    proxy: {
      "/devapi": {
        target: "https://127.0.0.0:8080",
        changeOrigin: true,
        rewrite: (path) => path.replace(new RegExp("^/devapi"), ""),
      },
    },
  },
};
